package com.magina.nety.config;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableCaching(proxyTargetClass = true)
public class CacheConfig {

        @Bean(name="simpleCacheManager")
        public CacheManager simpleCacheManager(){
            SimpleCacheManager cacheManager = new SimpleCacheManager();
            List<Cache> caches = new ArrayList<Cache>();
            ConcurrentMapCache cache1 = new ConcurrentMapCache("mycache");
            ConcurrentMapCache cache2 = new ConcurrentMapCache("mycache2");
            caches.add(cache1);
            caches.add(cache2);
            cacheManager.setCaches(caches);
            return cacheManager;
        }

}
